package com.golang.api.controller;

import com.golang.api.dto.request.OrderInfoCreateDto;
import com.golang.api.dto.response.order.CreateOrderDto;
import com.golang.api.service.IOrderService;
import com.golang.api.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    //下单
    @PostMapping(value = "/create")
    public Result<CreateOrderDto> create(@ModelAttribute OrderInfoCreateDto dto) throws Exception {
        log.info("创建订单:{}", dto);
        return orderService.create(dto);
    }


    //取消订单
    @PostMapping(value = "/cancel")
    public Result<Boolean> cancel(@RequestParam String orderId) throws Exception {
        log.info("取消订单:{}", orderId);
        return orderService.cancel(orderId);
    }


}
